<!doctype html>
<html>

<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>投稿</title>
    <link rel="stylesheet" type="text/css" href="../../css/api.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/style.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/member.css"/>
    <script type="text/javascript" src="../../script/jquery-1.9.1.min.js"></script>
    <script type="text/javascript" src="../../script/mobile.js"></script>
    <script type="text/javascript">
        window['adaptive'].desinWidth = 750;
        window['adaptive'].baseFont = 28;
        window['adaptive'].maxWidth = 750;
        window['adaptive'].init();
    </script>
</head>

<body>
<div id="header" style="height: 0.9rem; background: #fff; position: fixed; top: 0;left: 0; width: 100%; z-index: 99">
    <header class="header header-shadow">
        <div class="header-left">
            <div tapmode onclick="comeBack();" class="nav-left"><img class="icon-back" src="../../icon/icon-back.png"/>
            </div>
        </div>
        <h2>投稿</h2>
    </header>
</div>
<div class="header-h" style="padding-top: 1.5rem;"></div>

<section class="html_section pr30 pl30 ">
    <div class="mt20 f30">投稿类型（必选）</div>
    <ul class="yj_type mt20">

    </ul>
    <div class="mt30 f30">投稿内容</div>
    <textarea class="textbox1 mt20" placeholder="请输入你的稿子内容..." style="height: 1.84rem;"></textarea>
    <div class="mt30 f30">添加图片(选填)</div>
    <div class="activity-detail mt20">
        <ul id="icon_list">
            <!-- <li>
                <img src="../../image/img-media01.png" alt="">
                <div class="delete"></div>
            </li> -->
            <li class="choose-pic" id="choosePic" tapmode>
                <div class="pic-icon">拍照/照片<br/>（选填）</div>
            </li>
        </ul>
        <div tapmode class="btn1 mt60">发布</div>
    </div>
</section>

</body>

</html>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/common.js"></script>
<script type="text/javascript">
    var category_id = 1;
    apiready = function () {
        setFixStatusBar(); //设置状态栏
        keybackListener()
        ready();
    }

    function ready() {
        getAjax(Interface.get_contribute_type, {token: $api.getStorage('token'), type: 1}, function (res) {
            category_id = res.data[0].id;
            $.each(res.data, function (i, item) {
                if (i == 0) {
                    $(".yj_type").append('<li class="on" tapmode onclick="chooseType(this,' + item.id + ')" >' + item.title + '</li>');
                }
                else
                    $(".yj_type").append('<li tapmode onclick="chooseType(this,' + item.id + ')" >' + item.title + '</li>');
            })
        }, function (res, err) {
        })
    }

    function chooseType(e, id) {
        console.log(id);
        $(".yj_type li").removeClass("on");
        $(e).addClass("on");
        category_id = id;
    }

    $(".btn1").click(function () {
        var icon = '';
        var content = $("textarea").val();
        console.log(content);
        if (content == "") {
            pop.notice('请输入你的稿子内容');
            return;
        }
        if (category_id == "") {
            pop.notice('请选择投稿类型');
            return;
        }
        $("#icon_list li.img-li").each(function (i, item) {
            if (i == 0)
                icon = $(item).data("id");
            else
                icon += ',' + $(item).data("id");
        })
        pop.loading();
        getAjax(Interface.set_contribute, {
            token: $api.getStorage('token'),
            type: 1,
            category_id: category_id,
            content: content,
            icon: icon
        }, function (res) {
            pop.close();
            pop.notice('投稿成功', 1.3, function () {
                comeBack();
            })
        }, function (res, err) {
        })
    })

    $("#choosePic").click(function () {
        uploadbg();
    })

    function uploadbg() {
        uploadHeadPic(function (res) {
            console.log(jsonChange(res));
            $("#icon_list").prepend(' <li class="img-li" id="img_' + res.icon + '" data-id="' + res.icon + '"><img src="' + getImg(res.path) + '" alt=""><div tapmode onclick="delImg(' + res.icon + ')" class="delete"></div></li>');
        })
    }

    //删除图片
    function delImg(id) {
        $("#img_" + id).remove();
    }


</script>
